package tt.dz.egobus.servicemanager.business.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tt.dz.egobus.servicemanager.core.task.DynamicTaskManager;
import tt.dz.egobus.servicemanager.service.BusinessCacheService;
import tt.dz.egobus.servicemanager.service.DynamicTaskService;

/**
 * @author Anson
 * @date 17-8-9
 * @name 用户请求派单的时候的动态任务添加
 * 并做redis的任务存储
 * @since 1.0.6
 */
public class UserRequestGrabBusinessDynamicInitTask implements Runnable {
    private static final Logger LOGGER = LoggerFactory.getLogger(UserRequestGrabBusinessDynamicInitTask.class);

    private final UserRequestDynamicHandler handler;

    public UserRequestGrabBusinessDynamicInitTask(String businessId, BusinessCacheService businessCacheService,
                                                  DynamicTaskManager dynamicTaskManager, DynamicTaskService dynamicTaskService) {
        this.handler = new UserRequestDynamicHandler(businessId, businessCacheService,
                dynamicTaskManager, dynamicTaskService);
    }

    public UserRequestGrabBusinessDynamicInitTask(UserRequestDynamicHandler handler) {
        this.handler = handler;
    }

    @Override
    public void run() {
        LOGGER.info("当前businessId={},异步线程执行添加动态定时任务开始", handler.getBusinessId());
        handler.handler();
    }
}
